package com.dmzc.stage1.chapter1;

/***
 * 构造线程时直接传入一个Thread对象也可以实现资源共享的问题，但是与语义不符
 */
public class TicketWindow extends Thread{
    private int index = 1;
    private final int MAX_VALUE=2000;
    private synchronized void incre(){
        index++;
    }
    @Override
    public void run() {
        while (index < MAX_VALUE){
            System.out.println(currentThread().getName()+"curr"+index);
            incre();
        }
    }

    public static void main(String[] args) {
        TicketWindow t=new TicketWindow();
        Thread t1=new Thread(t,"t1");
        Thread t2=new Thread(t,"t2");
        Thread t3=new Thread(t,"t3");
        t1.start();
        t2.start();
        t3.start();
    }
}
